#include "../mqserver/mq_exchange.hpp"
#include "gtest/gtest.h"
#include <iostream>

mymq::ExchangeManager::Ptr emp;

class ExchangeTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        emp = std::make_shared<mymq::ExchangeManager>("./data/meta.db");
    }
    virtual void TearDown() override
    {
        emp->Destory();
        std::cout << "最后的清理！！\n";
    }
};

// TEST(exchange_test,insert_test)
// {
//     std::unordered_map<std::string,std::string> map= {{"k1","v1"},{"k2","v2"}};
//     emp->DeclareExchange("exchange1",mymq::ExchangeType::DIRECT,true,false,map);
//     emp->DeclareExchange("exchange2",mymq::ExchangeType::DIRECT,true,false,map);
//     emp->DeclareExchange("exchange3",mymq::ExchangeType::DIRECT,true,false,map);
//     ASSERT_EQ(emp->size(),3);
// }
TEST(exchange_test, select_test) {

    ASSERT_EQ(emp->exists("exchange1"), true);
    ASSERT_EQ(emp->exists("exchange2"), true);
    ASSERT_EQ(emp->exists("exchange3"), false);
    mymq::Exchange::Ptr exp = emp->SelectExchange("exchange2");
    ASSERT_NE(exp.get(), nullptr);
    ASSERT_EQ(exp->name, "exchange2");
    ASSERT_EQ(exp->durable, true);
    ASSERT_EQ(exp->auto_del, false);
    ASSERT_EQ(exp->type, mymq::ExchangeType::DIRECT);
    ASSERT_EQ(exp->GetArgs(), std::string("k1=v1&k2=v2&"));
}
TEST(exchange_test, remove_test) {
    emp->DeleteExchange("exchange2");
    mymq::Exchange::Ptr exp = emp->SelectExchange("exchange2");
    ASSERT_EQ(exp.get(), nullptr);
    ASSERT_EQ(emp->exists("exchange2"), false);
}
int main(int argc, char *argv[])
{
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    testing::InitGoogleTest(&argc,argv);
    RUN_ALL_TESTS();
    return 0;
}